﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
using MaterialDesignThemes.Wpf;
using MyFirstWPF.View.Compnent;
using MyFirstWPF.ViewModel;
using System.Threading.Tasks;

namespace MyFirstWPF.View
{
    /// <summary>
    /// Page1.xaml 的交互逻辑
    /// </summary>
    public partial class Page1 : Page
    {
        public static string dbPath = "../../studyPlan.db";

        public Page1()
        {
            InitializeComponent();           
            reInitCards();
        }

        //初始化卡片,数据取出
        public void reInitCards()
        {
            wp1.Children.Clear();
            using (var db = new StudyPlanDb(dbPath))
            {
                List<TaskInfo> taskList = db.MyQuery<TaskInfo>(x=>x.userId == LoginView.myId && x.GetEndTime() > DateTime.Now).ToList();
                taskList.Reverse();
                foreach (TaskInfo items in taskList)
                {
                    if (items.isFinished == 0)
                    {
                        wp1.Children.Add(new UserControl1(items));
                    }
                }                               
            }           
        }

        private void Bt_Click(object sender, RoutedEventArgs e)
        {
            throw new NotImplementedException();
        }

        private void BtnAddTask_Click(object sender, RoutedEventArgs e)
        {
            DialogHost.OpenDialogCommand.Execute(new AddTask(this),null);
        }
    }
}
